package mycompiler.lexicalAnalysis;

import junit.framework.TestCase;

public class TokenProduceTestUpdate extends TestCase {
	
	TokenProduce tp1;
	String s;

	protected void setUp() throws Exception {
		tp1 = new TokenProduce(s);
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testGetNextChar() {
		char []c = {'a', 'b', ' ', 'c'};
		int srcLength = 10;
		int charNm = 0;
		char rightChar = 'a';
		char falseChar = '1';
		
		assertEquals(this.lengthAllZero(tp1.getNextChar(c)), true);
		
		//test the c[0] is 'a' and it's true;
		assertEquals(this.forTestGetNextChar(tp1, srcLength, charNm, c, rightChar), true);
		
		//test the c[1] is '1',but it's wrong;
		assertEquals(this.forTestGetNextChar(tp1, srcLength, charNm, c, falseChar), false);
	}

	public void testUngetNextChar() {
		int charNm = 10;
		
		//set tp1's EOF false, and the charNumber--,so the func"for..." returns true;
		assertEquals(this.forTestUngetNextChar(tp1, charNm, false), true);
		
		//set tp1's EOF true ,so the charNumber isn't self-minusing,and the func"for..." returns false;
		assertEquals(this.forTestUngetNextChar(tp1, charNm, true), false);
		//fail("Not yet implemented");
	}

	//test the nextchar if the right char and return true or false;
	public boolean forTestGetNextChar(TokenProduce tp, int sourceL, int charNo, char[]cl, char c)
	{
		tp.sourceLength = sourceL;
		tp.charNumber = charNo;
		if(tp.getNextChar(cl) == c)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//set charNumber and sourceLength both zero for func"getNextChar()";
	public boolean lengthAllZero(char c1 )
	{		
		if(c1 == ' ')
		{
			return true;
		}
		else
		{
			return false;
		}	 
	}
	
	//set charNumber a number,and test if the charNumber was minused;
	public boolean forTestUngetNextChar(TokenProduce tp, int charNo, boolean bl)
	{
		tp.EOF = bl;
		tp.charNumber = charNo;
		tp.ungetNextChar();
		if(tp.charNumber == (charNo -1))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
